#include "leftform.h"
#include "ui_leftform.h"

leftForm::leftForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::leftForm)
{
    ui->setupUi(this);
    initPropertyAnimation();
}

leftForm::~leftForm()
{
    delete ui;
}

void leftForm::setIconAndText(const QString &text, const QString &img, int pageIndex)
{
    ui->text->setText(text);
    ui->img->setPixmap(QPixmap(img));
    ui->img->setScaledContents(true);
    this->pageIndex = pageIndex;
}

void leftForm::mousePressEvent(QMouseEvent *event)
{
    ui->widget_6->setStyleSheet("#widget_6{background-color:rgba(0, 190, 255, 125);}");
    emit pageChange(pageIndex);
    emit leftClicked(true);
}

int leftForm::getpageIndex()
{
    return pageIndex;
}

void leftForm::clearStyle()
{
    ui->widget_6->setStyleSheet("#widget_6{background-color:rgb(236, 236, 236);}");
}

void leftForm::initPropertyAnimation()
{
    ui->widget->hide();
    animation = new QPropertyAnimation(ui->label,"geometry",this);
    animation->setDuration(1200);
    animation->setKeyValueAt(0,QRect(1,0,5,50));
    animation->setKeyValueAt(0.5,QRect(1,50,5,0));
    animation->setKeyValueAt(1,QRect(1,0,5,50));
    animation->setLoopCount(-1);
    animation->start();

    animation = new QPropertyAnimation(ui->label_2,"geometry",this);
    animation->setDuration(1300);
    animation->setKeyValueAt(0,QRect(9,0,5,50));
    animation->setKeyValueAt(0.5,QRect(9,50,5,0));
    animation->setKeyValueAt(1,QRect(9,0,5,50));
    animation->setLoopCount(-1);
    animation->start();

    animation = new QPropertyAnimation(ui->label_3,"geometry",this);
    animation->setDuration(1400);
    animation->setKeyValueAt(0,QRect(17,0,5,50));
    animation->setKeyValueAt(0.5,QRect(17,50,5,0));
    animation->setKeyValueAt(1,QRect(17,0,5,50));
    animation->setLoopCount(-1);
    animation->start();

    animation = new QPropertyAnimation(ui->label_4,"geometry",this);
    animation->setDuration(1500);
    animation->setKeyValueAt(0,QRect(25,0,5,50));
    animation->setKeyValueAt(0.5,QRect(25,50,5,0));
    animation->setKeyValueAt(1,QRect(25,0,5,50));
    animation->setLoopCount(-1);
    animation->start();

    animation = new QPropertyAnimation(ui->label_5,"geometry",this);
    animation->setDuration(1600);
    animation->setKeyValueAt(0,QRect(33,0,5,50));
    animation->setKeyValueAt(0.5,QRect(33,50,5,0));
    animation->setKeyValueAt(1,QRect(33,0,5,50));
    animation->setLoopCount(-1);
    animation->start();
}

void leftForm::showAnimation(bool isShowing)
{
    if(isShowing)
        ui->widget->show();
    else
        ui->widget->hide();
}
